package com.zc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zc.mapper.StuTestMapper;
import com.zc.pojo.StuTest;
import com.zc.service.StuTestService;
import com.zc.utils.ZCProperries;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class StuTestServiceImpl implements StuTestService {

    @Autowired
    private StuTestMapper stuTestMapper;

    @Autowired
    private ZCProperries zcProperries;

    @Override
    public void stuTestSave(StuTest stuTest) {
        stuTestMapper.insert(stuTest);
    }

    @Override
    public StuTest queryById(String id) {
        return stuTestMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<StuTest> query(String name, String sex) {
        Example example = new Example(StuTest.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("name",name);
        criteria.andEqualTo("sex",sex);
        List<StuTest> stuTestList = stuTestMapper.selectByExample(example);
        return stuTestList;
    }

    @Override
    public List<StuTest> queryByid(String id) {
        return stuTestMapper.getStuTestById(id);
    }

    @Override
    public PageInfo<StuTest> queryByPage(Integer pageNum) {

        PageHelper.startPage(pageNum,zcProperries.getPageSize());

        List<StuTest> stuTestList = stuTestMapper.selectAll();
        PageInfo<StuTest> pageInfo = new PageInfo<>(stuTestList);
        return pageInfo;
    }
}
